package mks.webshop.gaedao;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.List;

import mks.webshop.common.AC;
import mks.webshop.dao.DaoManager;
import mks.webshop.dao.IMasterDao;
import mks.webshop.entity.Category;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig;
import com.google.appengine.tools.development.testing.LocalServiceTestHelper;

public class GAEMstDaoPrepareData {
    private final LocalServiceTestHelper helper = new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig());
    IMasterDao iMstDao = DaoManager.getMasterDaoInst();
    
    @Before
    public void setUp() throws Exception {
        helper.setUp();
    }

    @After
    public void tearDown() throws Exception {
        helper.tearDown();
    }

    @Test
    public void testPrepareCategory01() {
        // Level 1 
        Category cat1 = new Category();
        cat1.setId("AB");
        cat1.setName("Đồ gia dụng");
        cat1.setLevel(1);
        cat1.setLang(AC.VN);
        cat1.setOrderNo(1);
        
        assertTrue(iMstDao.saveCat(cat1));
        
        Category cat2 = new Category();
        cat2.setId("AB");
        cat2.setName("Đồ làm vườn");
        cat2.setLevel(1);
        cat2.setLang(AC.VN);
        cat2.setOrderNo(2);
        
        assertTrue(iMstDao.saveCat(cat2));
        
        Category cat1_1 = new Category();
        cat1_1.setParentId("AB");
        cat1_1.setId("AB001");
        cat1_1.setName("Dụng cụ nấu");
    }
    
    @Test
    public void testGetPrepareCategory01() {
        List<Category> catList = iMstDao.getCategoryList();
        for (Category cat : catList) {
            System.out.println("" + cat.getKey() + ";" + cat.getName());
        }
        
        assertEquals(2, catList.size());
        
        // List<Category> subCatList = iMstDao.getSubCategoryList("AB");
    }    
}
